<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./node_modules/axios/dist/axios.min.js"></script>
  </head>
  <body>
    <h1>修改用户</h1>
    <label for="username">用户名:</label>
    <input type="text" id="username" name="username" /><br /><br />
    <label for="password">密码:</label>
    <input type="password" id="password" name="password" /><br /><br />
    <button>提交</button>
    <script>
      const username = document.getElementById("username");
      const password = document.getElementById("password");
      const button = document.querySelector("button");
      const num=location.search.split("=")[1];
      axios.get(`http://localhost:3000/users/${num}`).then(res => {
        username.value = res.data.username;
        password.value = res.data.password;
      })
      button.addEventListener("click", () => {
        axios({
          url: `http://localhost:3000/users/${num}`,
          method: "put",
          data: {
            username: username.value,
            password: password.value
          }
        }).then(res => {
        location.href = "./index.html";
        })
      })
    </script>
  </body>
</html>
